package cn.cvs.servlet;

import cn.cvs.dao.sysUser.CardMapper;
import cn.cvs.pojo.Card;
import cn.cvs.service.CardService;
import cn.cvs.utils.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/AddServlet")
public class AddServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        CardService cardService = new CardService();
        Card card = new Card();
        card.setUserName(request.getParameter("userName"));
        card.setIdNumber(request.getParameter("idNumber"));
        card.setStatus(1);
        card.setCreateDate(request.getParameter("createDate"));
        int count = cardService.add(card);
        if (count>0){
            request.setAttribute("info","添加成功！");
        }else {
            request.setAttribute("info","添加失败！");
        }
        request.getRequestDispatcher("ListServlet").forward(request,response);
    }
}
